/**
 * author      : dormi330
 * date        : 2018/6/24
 * project     : mybatis
 * description : 移除一个 购物车中的 sku
 */

package com.deep.trade.application.cart;

import com.deep.trade.adaptor.required.IdService;
import com.deep.trade.application.CartServiceFacade;
import com.deep.trade.cart.InDtoCart;
import com.deep.trade.cart.InDtoCartDelete;
import com.deep.trade.cart.query.OutDtoCartItem;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class CartBaseOperatio {

    protected Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    protected CartServiceFacade cartServiceFacade;

    protected String tenantCode = IdService.TENANT_CODE;
//    protected String memberId = IdService.MEMBER_ID;
    protected String token = IdService.TOKEN;
    protected String skuId = IdService.SKU_1_ID;
    protected int quantityAdd = 10;
    protected int quantityAlterTo = 100;
    protected int quantityRemove = 1;

    // 添加sku到购物车
    protected void addSkuToCart() throws Exception {
        InDtoCart inDtoCart = new InDtoCart(tenantCode, token, skuId, quantityAdd);
        cartServiceFacade.addSkuToCart(inDtoCart);
    }

    // 查询
    protected List<OutDtoCartItem> cartOfMember() throws Exception {
        PageInfo<OutDtoCartItem> outDtoCartItemPage = cartServiceFacade.cartOfMember(tenantCode, token, 10, 1);
        return outDtoCartItemPage.getList();
    }

    // 修改数量
    protected void alterQuantity() throws Exception {
        InDtoCart inDtoCart = new InDtoCart(tenantCode, token, skuId, quantityAlterTo);
        cartServiceFacade.alterQuantity(inDtoCart);
    }

    // 移除
    public void removeSkuFromCart() throws Exception {
        List<String> skuIdList = new ArrayList<>(1);
        skuIdList.add(skuId);
        InDtoCartDelete inDtoCartDelete = new InDtoCartDelete(tenantCode, token, skuIdList, quantityRemove);
        cartServiceFacade.removeSkuFromCart(inDtoCartDelete);
    }
}
